package com.component.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.component.domain.base.DataBase;
import com.component.service.MChannelService;
import com.system.config.SpringContextUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/4/29 21:07
 * @since JDK 1.8
 */
@TableName("m_note")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Note extends DataBase {

    /**
     * 主键id
     */
    @TableId(type = IdType.AUTO)
    private Integer id;

    /**
     * 标题
     */
    @TableField("title")
    private String title;

    /**
     * 标签
     */
    @TableField("tag")
    private String tag;

    /**
     * 浏览次数
     */
    @TableField("viewnum")
    private Integer viewnum;

    @TableField("isencrypt")
    private Boolean isEncrypt;

    @TableField("channelid")
    private String channelId;

    @TableField(exist = false)
    private String channelName;

    @TableField(exist = false)
    private MChannel mChannel;

    /**
     * 修改地址
     */
    @TableField(exist = false)
    private String updateUrl;

    /**
     * 打开地址
     */
    @TableField(exist = false)
    private String contentUrl;

    @TableField("userid")
    private String userid;

    @TableField(exist = false)
    private String subcontent;

    @TableField("change_status")
    private String changeStatus;

    @TableField("status")
    private String status;

    @TableField("isprivate")
    private Boolean isprivate;

    @TableField("datatype")
    private String datatype;

    public String getUpdateUrl(){
        return "/update?id="+this.id;
    }

    public String getContentUrl(){
        return "/getcontent?id="+this.id;
    }

    public MChannel getmChannel() {
        if(mChannel==null && StringUtils.isNotBlank(channelId)){
            MChannelService mChannelService= SpringContextUtils.getBean(MChannelService.class);
            MChannel mChannel=mChannelService.getById(this.channelId);
            this.mChannel=mChannel;
            this.channelName=mChannel.getChannelname();
        }
        return this.mChannel;
    }




}
